new Vue({
    el: '#app',
    data() {
        return {
            pickerOptions: pickerOptions,
            form: {
                object_id: '201922222',
                object_type: "contract",
                enterprise_info_serialnumber: $.cookie('enterprise'),
                approval_info_id: "",
                founder: $.cookie('use'),
            },
            Data: [],
            loading: false,
            isWindow: window.innerWidth < 768 ? true : false
        }
    },
    mounted() {
        window.addEventListener('resize', () => {
            this.isWindow = window.innerWidth < 768 ? true : false
        });
        const flow_id = sessionStorage.getItem("flow_id")
        this.getData(flow_id);
    },
    methods: {
        getData(flow_id) {
            const _this = this;
            this.Data = [
                {
                    "Approver_Time": "2024-06-14 17:36:55",
                    "Approver_User_Id": "Admin",
                    "Approver_Opinions": "首次提交",
                    "Node_id": "1",
                    "name": "平台管理员",
                    "examineMode": "",
                    "Node_name": "发起人",
                    "Current_Node_Approver_Type": "0",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:37:35",
                    "Approver_User_Id": "Admin1",
                    "Approver_Opinions": "同意",
                    "Node_id": "2",
                    "name": "平台管理员1",
                    "examineMode": "1",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:37:12",
                    "Approver_User_Id": "Admin",
                    "Approver_Opinions": "同意",
                    "Node_id": "2",
                    "name": "平台管理员",
                    "examineMode": "1",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:03",
                    "Approver_User_Id": "Admin2",
                    "Approver_Opinions": "123已同意",
                    "Node_id": "3",
                    "name": "平台管理员2",
                    "examineMode": "2",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "自动同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:03",
                    "Approver_User_Id": "123",
                    "Approver_Opinions": "同意",
                    "Node_id": "3",
                    "name": "测试123",
                    "examineMode": "2",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:04",
                    "Approver_User_Id": "Admin",
                    "Approver_Opinions": "自动审批通过",
                    "Node_id": "4",
                    "name": "平台管理员",
                    "examineMode": "1",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:05",
                    "Approver_User_Id": "Admin1",
                    "Approver_Opinions": "自动审批通过",
                    "Node_id": "5",
                    "name": "平台管理员1",
                    "examineMode": "1",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:05",
                    "Approver_User_Id": "123",
                    "Approver_Opinions": "自动审批通过",
                    "Node_id": "5",
                    "name": "测试123",
                    "examineMode": "1",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:04",
                    "Approver_User_Id": "Admin",
                    "Approver_Opinions": "自动审批通过",
                    "Node_id": "5",
                    "name": "平台管理员",
                    "examineMode": "1",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:06",
                    "Approver_User_Id": "Admin1",
                    "Approver_Opinions": "自动审批通过",
                    "Node_id": "6",
                    "name": "平台管理员1",
                    "examineMode": "2",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": "同意"
                },
                {
                    "Approver_Time": "2024-06-14 17:38:06",
                    "Approver_User_Id": "Admin",
                    "Approver_Opinions": "拒绝大武口打包",
                    "Node_id": "6",
                    "name": "平台管理员",
                    "examineMode": "2",
                    "Node_name": "审批人",
                    "Current_Node_Approver_Type": "1",
                    "Approver_Result": ""
                },{
                    "Approver_Time": "",
                    "Approver_User_Id": "",
                    "Approver_Opinions": "",
                    "Node_id": "7",
                    "name": "平台管理员",
                    "examineMode": "2",
                    "Node_name": "抄送人",
                    "Current_Node_Approver_Type": "2",
                    "Approver_Result": ""
                }
            ]
            // $.ajax({
            //     headers,
            //     url: BASE_URL + '/Flow/getFlowAllMsg',
            //     type: 'POST',
            //     data: {
            //         flow_id
            //     },
            //     success: function (res) {
            //         if (res.status == 0) {
            //             _this.Data = res.data;
            //         }else{
            //             _this.$message.error("操作失败，请稍后再试")
            //         }
            //     },
            //     error: function () {
            //         _this.$message.error("操作失败，请稍后再试")
            //     },
            //     complete: function (XMLHttpRequest) {
            //         if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            //             window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            //         }
            //     }
            // })
        },
        submitForm(formName) {
            let _this = this
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    _this.loading = true
                    _this.form.arlist = _this.config(_this.data);
                    console.log(_this.form);
                    $.ajax({
                        headers: {
                            ...headers,
                            'Content-Type': 'application/json;charset=UTF-8'
                        },
                        url: BASE_URL + '/Flow/addNewApprova',
                        type: 'POST',
                        data: JSON.stringify(_this.form),
                        success: function (res) {
                            if (res.status == 0) {
                                _this.submit(res.data);
                            } else {
                                _this.$message.error("操作失败，请稍后再试")
                            }
                        },
                        error: function () {
                            _this.$message.error("操作失败，请稍后再试")
                        },
                        complete: function (XMLHttpRequest) {
                            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                                window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                            }
                        }
                    })
                } else {
                    console.log("error submit!!");
                    return false;
                }
            });
        },
        submit(data) {//首次申请提交
            const _this = this;
            console.log({
                "userId": $.cookie('use'),
                "approver_opinions": "首次提交",
                "approver_result": "1", //1 同意 2.拒绝 3.移交
                "founder": [], //如果移交选移交人
                "flow_id": data.Approval_Record_SerialNumber, //整个流程Approval_Record_SerialNumber
                "onApproval_record_detail_id": data.Approval_Record_Detail_SerialNumber //当前节点Approval_Record_Detail_SerialNumber
            });
            $.ajax({
                headers: {
                    ...headers,
                    'Content-Type': 'application/json;charset=UTF-8'
                },
                url: BASE_URL + '/Flow/commitApprova',
                type: 'POST',
                data: JSON.stringify({
                    "userId": $.cookie('use'),
                    "approver_opinions": "首次提交",
                    "approver_result": "1", //1 同意 2.拒绝 3.移交
                    "founder": [], //如果移交选移交人
                    "flow_id": data.Approval_Record_SerialNumber, //整个流程Approval_Record_SerialNumber
                    "onApproval_record_detail_id": data.Approval_Record_Detail_SerialNumber //当前节点Approval_Record_Detail_SerialNumber
                }),
                success: function (res) {
                    console.log(res);
                    if (res.status == 0) {
                        _this.$message.success(res.msg)
                        window.history.go(-1);
                    } else {
                        _this.$message.error("操作失败，请稍后再试")
                    }
                },
                error: function () {
                    _this.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                    _this.loading = false;
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                }
            })
        },
        deal() {
            const modify = deepClone(this.form)
            return { add: "", modify };
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
    }
})